package com.linln.admin.notice.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.linln.modules.member.domain.Notice;
import com.linln.modules.member.service.NoticeService;

/**
 * @author hct
 * @date 2019/10/11
 */
@Controller
@RequestMapping("/notice/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    /**
     * 列表页面
     */
    @GetMapping("/index")
    @RequiresPermissions("notice:notice:index")
    public String index(Model model, Notice notice) {

        // 创建匹配器，进行动态查询匹配
        ExampleMatcher matcher = ExampleMatcher.matching();

        // 获取数据列表
        Example<Notice> example = Example.of(notice, matcher);
        Page<Notice> list = noticeService.getPageList(example);

        // 封装数据
        model.addAttribute("list", list.getContent());
        model.addAttribute("page", list);
        return "/notice/notice/index";
    }

    /**
     * 跳转到添加页面
     */
    @GetMapping("/add")
    @RequiresPermissions("notice:notice:add")
    public String toAdd() {
        return "/notice/notice/add";
    }

    /**
     * 跳转到编辑页面
     */
    @GetMapping("/edit/{id}")
    @RequiresPermissions("notice:notice:edit")
    public String toEdit(@PathVariable("id") Notice notice, Model model) {
        model.addAttribute("notice", notice);
        return "/notice/notice/add";
    }

   

    /**
     * 跳转到详细页面
     */
    @GetMapping("/detail/{id}")
    @RequiresPermissions("notice:notice:detail")
    public String toDetail(@PathVariable("id") Notice notice, Model model) {
        model.addAttribute("notice",notice);
        return "/notice/notice/detail";
    }

    
}